package com.example.shardings.ms.service;

import com.example.shardings.ms.mapper.WechatUserMapper;
import com.example.shardings.ms.pojo.WechatUser;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class WechatUserService {

    @Autowired
    private WechatUserMapper wechatUserMapper;

    public List<WechatUser> getAll() {
        PageHelper.startPage(1,5);
        PageHelper.orderBy(" id asc,sort asc  ");
        WechatUser s=new WechatUser();
        return  wechatUserMapper.select(s);
    }

    public List<WechatUser> getById(Long id) {
        PageHelper.startPage(1,3000);
        PageHelper.orderBy(" sort asc,id asc  ");
        WechatUser s=new WechatUser();
        s.setId(id);
        return  wechatUserMapper.select(s);
    }

    public  List<WechatUser>  initDate(Integer total){
        List<WechatUser> rs=new ArrayList<>();
        for(int i=10;i<total;i++){
            WechatUser d=new WechatUser();
            //正式生产,应该用全局id生成器
            //d.setId((long) i);
            wechatUserMapper.insertSelective(d);
            rs.add(d);
        }
        return rs;
    }
}
